﻿<%@ Page Title="查看视频" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="ViewVideo.aspx.cs" Inherits="Xpus.YouYTube.WebSite.Views.Video.ViewVideo" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<% TVideo video = (TVideo)ViewData["Video"]; %>
    <div class="box">
		<div class="bt">查看视频</div>
		<div class="bc">
			<h2 class="doctitle"><%= HttpUtility.HtmlEncode(video.Title) %></h2>
			<% if (video.UserName != "") %>
			<% { %>
				<p class="tk">感谢<span class="ru">
				<% if (video.UserUrl != "") %>
				<% { %>
					<a href="<%= video.UserUrl %>" target="_blank"><%= HttpUtility.HtmlEncode(video.UserName)%></a>
				<% } %>
				<% else %>
				<% { %>
					<%= HttpUtility.HtmlEncode(video.UserName)%>
				<% } %>
				</span>的推荐。</p>
			<% } %>
			<p style="text-align:center"><%= video.EmbeddedCode %></p>
			<p class="vvote">
				<span><a href="javascript:voteVideo(<%= video.Id %>, 'agree')">顶Y的 (<span id="van"><%= video.AgreeNumber %></span>)</a></span>
				<span><a href="javascript:voteVideo(<%= video.Id %>, 'disagree')">踩Y的 (<span id="vdn"><%= video.DisagreeNumber %></span>)</a></span>
			</p>
			<p class="des">
				<%= HttpUtility.HtmlEncode(video.Description).Replace("\r\n", "<br/>") %>
				<span class="vtm">◆ <%= video.AddedTime.ToString("yyyy-MM-dd HH:mm:ss") %></span>
			</p>
			<p class="des">原视频地址：<a href="<%= video.Source %>" target="_blank"><%= HttpUtility.HtmlEncode(video.Source) %></a></p>
		</div>
    </div>
	<div class="ad-c">
<script type="text/javascript"><!--
google_ad_client = "pub-0410788977836329";
/* 468x60, 创建于 08-6-5,yyt，首页栏目间 */
google_ad_slot = "2133264878";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
	</div>
    <div class="box">
		<div class="bt">发表评论</div>
		<div class="bc">
<form id="commentForm" action="/Comment/CommentSubmit/" method="post">
	<input type="hidden" name="svideoId" value="<%= video.Id %>" />
	<table>
		<tr><td>您的大名：</td><td><input type="text" style="width:200px" name="userName" maxlength="50" class="txt" /></td></tr>
		<tr><td>您的高见：</td><td><textarea name="body" style="width:400px;height:150px" class="txt" ></textarea></td></tr>
		<tr><td>验证码：</td><td>
			<script type="text/javascript">
			var RecaptchaOptions = {
			   theme : 'white'
			};
			</script>
			<script type="text/javascript"
			   src="http://api.recaptcha.net/challenge?k=<%= TReCaptcha.PublicKey %>">
			</script>
			<noscript>
			   <iframe src="http://api.recaptcha.net/noscript?k=<%= TReCaptcha.PublicKey %>"
				   height="300" width="500" frameborder="0"></iframe><br>
			   <textarea name="recaptcha_challenge_field" rows="3" cols="40">
			   </textarea>
			   <input type="hidden" name="recaptcha_response_field" 
				   value="manual_challenge">
			</noscript>
		</td></tr>
	</table>
</form>
<p><button id="btnSubmit">发表评论</button><span id="retmsg"></span></p>
		</div>
    </div>
    <div class="box">
		<div class="bt">评论 [<a href="javascript:getComments(1)">刷新</a>]</div>
		<div class="bc">
			<div id="waitingCommentsPanel" style="display:none">
				<img src="/Content/Images/loading.gif" alt="loading..." />
				正在加载评论……
			</div>
			<div id="commentsPanel">
			</div>
		</div>
    </div>
    
<script type="text/javascript">
var theCommentForm;
var theRetmsg;
var theCommentButton;
var theCommentsPanel;
var theWaitingCommentsPanel;

function getEl()
{
	theCommentForm = YAHOO.util.Dom.get("commentForm");
	theRetmsg = YAHOO.util.Dom.get("retmsg");
	theCommentButton = YAHOO.util.Dom.get("btnSubmit");
	theCommentsPanel = YAHOO.util.Dom.get("commentsPanel");
	theWaitingCommentsPanel = YAHOO.util.Dom.get("waitingCommentsPanel");
}

function setCommentRetMsg(msg, isErr)
{
	theRetmsg.innerText = msg;
	
	if(isErr)
		theRetmsg.className = "err";
	else
		theRetmsg.className = "suc";
}

function makeComment()
{
	theCommentButton.disabled = true;
	var callback =   
	{   
		success: function(o)
		{
			var s = o.responseText;
			var s0 = s.substr(0,1);
			if(s0 == 'T')
			{
				setCommentRetMsg(s.substr(1, s.length - 1), false);
				theCommentForm.reset();
				
				getComments(-1);
			}
			else if(s0 == 'F')
				setCommentRetMsg(s.substr(1, s.length - 1), true);
			else
				setCommentRetMsg("[未知响应] " + s, true);
				
			theCommentButton.disabled = false;
		},
		failure: function(o)
		{
			setCommentRetMsg("评论失败，连接错误。", true);
			theCommentButton.disabled = false;
		},
		timeout: 30000
	};
	var pdata = YAHOO.util.Connect.setForm(theCommentForm);
	YAHOO.util.Connect.asyncRequest("POST", "/Comment/CommentSubmit/", callback, null);
}

function init()
{
	getEl();
	YAHOO.util.Event.addListener(theCommentButton, "click", makeComment);
	
	getComments(1);
}

YAHOO.util.Event.onDOMReady(init);

function getComments(pi)
{
	var id = <%= video.Id %>;
	var psz = 100;
	
	var svrurl = "/Comment/GetComments/?svideoId="+id+"&spageIndex="+pi+"&spageSize="+psz+"&p="+Math.random();
	
	theWaitingCommentsPanel.style.display = "block";
	theCommentsPanel.innerText = '';
	
	var callback = 
	{
		success: function(o)
		{
			theWaitingCommentsPanel.style.display = "none";
			
			var s = o.responseText;
			var s0 = s.substr(0,1);
			if(s0 == 'T')
			{
				displayComments(s.substr(1,s.length-1));
			}
			else if(s0 == 'F')
			{
				theCommentsPanel.innerText = "错误：" + s.substr(1,s.length-1);
			}
			else
			{
				theCommentsPanel.innerText = "错误：[未知响应] " + s;
			}
		},
		failure: function(o)
		{
			theWaitingCommentsPanel.style.display = "none";
			
			theCommentsPanel.innerText = "错误：连接错误。";
		},
		timeout: 120000
	};
	YAHOO.util.Connect.asyncRequest("GET", svrurl, callback, null);
}

function displayComments(json)
{
	var o = YAHOO.lang.JSON.parse(json);
	
	if(o.Comments.length == 0)
	{
		theCommentsPanel.innerText = "暂无评论。";
		return;
	}
	
	for(var i in o.Comments)
	{
		var c = o.Comments[i];
		
		var cd = document.createElement("div");
		var ch = document.createElement("p");
		var cb = document.createElement("p");
		var cc = document.createElement("p");
		
		ch.className = "cmt";
		ch.innerHTML = "<span class='cmtid'>编号#" + c.Id + "</span> ";
		if(c.UserName == '')
			ch.innerHTML += "<span class='cmtnun'>[匿名用户]</span> ";
		else
			ch.innerHTML += "[<span class='cmtun'>" + c.UserName + "</span>] ";
		ch.innerHTML += "于 " + c.AddedTime + " 说：";
		
		cb.className = "cmtbd";
		cb.innerHTML = c.Body;
		
		cc.className = "cmd";
		cc.innerHTML = "<a href=\"javascript:voteComment(" + c.Id + ",'agree')\">支持</a>(<span id='can_" + c.Id +"'>" + c.Anumber + "</span>) ";
		cc.innerHTML += "<a href=\"javascript:voteComment(" + c.Id + ",'disagree')\">反对</a>(<span id='cdn_" + c.Id + "'>" + c.Dnumber + "</span>) ";
		cc.innerHTML += "<a href=\"javascript:voteComment(" + c.Id + ",'report')\">举报</a>";
		
		cd.appendChild(ch);
		cd.appendChild(cb);
		cd.appendChild(cc);
		
		theCommentsPanel.appendChild(cd);
		theCommentsPanel.appendChild(document.createElement("hr"));
	}
	
	var cp = document.createElement("div");
	cp.className = "vcp";
	for(var pi = 1; pi <= o.TotalPages; pi++)
	{
		var cpp = document.createElement("span");
		
		if(pi == o.PageIndex)
		{
			cpp.className = "curp";
			cpp.innerHTML = pi;
		}
		else
		{
			cpp.className = "comp";
			cpp.innerHTML = ("<a href='javascript:getComments(" + pi + ")'>" + pi + "</a>");
		}
		cp.appendChild(cpp);
	}
	theCommentsPanel.appendChild(cp);
}

var videovoted = false;
function voteVideo(id,type)
{
	if(videovoted)
	{
		alert('请不要重复操作。');
		return;
	}
	
	var svrurl;
	if(type == "agree")
		svrurl = "/Vote/AgreeVideo/" + id + "?p=" + Math.random();
	else if(type == "disagree")
		svrurl = "/Vote/DisagreeVideo/" + id + "?p=" + Math.random();
	else
		return;
		
	var callback =
	{
		success: function(o)
		{
			var s = o.responseText;
			var s0 = s.substr(0,1);
			if(s0 == 'T')
			{
				var snums = s.substr(1,s.length-1);
				var ss = snums.split(',');
				YAHOO.util.Dom.get("van").innerText = ss[0];
				YAHOO.util.Dom.get("vdn").innerText = ss[1];
				
				alert('谢谢您的参与！');
				videovoted = true;
			}
			else if(s0 == 'F')
				alert(s.substr(1,s.length-1));
			else
				alert('[未知响应] ' + s);
		},
		failure: function(o)
		{
			alert('发生了未知错误！');
		},
		timeout: 30000
	};
	YAHOO.util.Connect.asyncRequest("GET", svrurl, callback, null);
}

var commentsVoted = new Array();
function voteComment(id,type)
{
	for(var i in commentsVoted)
		if(commentsVoted[i] == id)
		{
			alert('请不要重复操作。');
			return;
		}
	
	var svrurl;
	if(type == "agree")
		svrurl = "/Vote/AgreeComment/"+id+"?p="+Math.random();
	else if(type == "disagree")
		svrurl = "/Vote/DisagreeComment/"+id+"?p="+Math.random();
	else if(type == "report")
		svrurl = "/Vote/ReportComment/"+id+"?p="+Math.random();
	else
		return;
		
	var callback =
	{
		success: function(o)
		{
			var s = o.responseText;
			var s0 = s.substr(0,1);
			if(s0 == 'T')
			{
				var snums = s.substr(1, s.length-1);
				var ss = snums.split(',');
				YAHOO.util.Dom.get("can_"+id).innerText = ss[0];
				YAHOO.util.Dom.get("cdn_"+id).innerText = ss[1];
				
				alert('谢谢您的参与！');
				commentsVoted.push(id);
			}
			else if(s0 == 'F')
				alert(s.substr(1,s.length-1));
			else
				alert('[未知响应] ' + s);
		},
		failure: function(o)
		{
			alert('发生了未知错误！');
		},
		timeout: 30000
	};
	YAHOO.util.Connect.asyncRequest("GET", svrurl, callback, null);
}
</script>
</asp:Content>
